﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace CalcCalorie
{
    public partial class FormCld : Form
    {
        bool bOk = false;

        public DateTime SelectedDate { get { return cld.SelectionStart; } }

        public FormCld()
        {
            InitializeComponent();
        }


        public bool ShowDialog(DateTime StartDate, int Top, int Left)
        {
            this.Top = Top;
            this.Left = Left;
            if (StartDate != null)
            { 
                cld.SelectionRange = new SelectionRange(StartDate, StartDate); 
            }
            else
            {
                cld.SelectionRange = new SelectionRange(DateTime.Today, DateTime.Today); 
            }
            bOk = false;
            ShowDialog();
            return bOk;
        }

        private void monthCalendar1_KeyDown(object sender, KeyEventArgs e)
        {

        }

        private void monthCalendar1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                e.IsInputKey = false;
                bOk = true;
                Close();
            }

            if (e.KeyCode == Keys.Escape)
            {
                e.IsInputKey = false;
                Close();
            }
        }

        private void cld_DateChanged(object sender, DateRangeEventArgs e)
        {
        }

        private void cld_DateSelected(object sender, DateRangeEventArgs e)
        {
            bOk = true;
            Close();
        }
    }
}
